import {defineConfig} from 'vite'
import vue from '@vitejs/plugin-vue'
import nodeResolve from "rollup-plugin-node-resolve";


const {resolve} = require('path')

// module.exports = {runtimeCompiler: false} // 确定是运行时候编译

//https://cn.vitejs.dev/config/
export const baseConfig = defineConfig({
    plugins: [
        nodeResolve(),
        // have to
        vue(),
    ],
    css: {
        // preprocessorOptions: {
        //     less: {
        //         modifyVars: {},
        //         javascriptEnabled: true,
        //         additionalData: `@import "src/styles/var.less";`
        //     }
        // }
    },
    resolve: {
        // alias: {
        //     '@': resolve(__dirname, './src'),
        //     '@/*': resolve(__dirname, './src/*'),
        //     '~': resolve(__dirname, './packages'),
        //     '~/*': resolve(__dirname, './packages/*'),
        //
        // },
        alias: [
            {
                find: /\/#\//,
                replacement: resolve("types") + "/"
            },
            {
                find: "@",
                replacement: resolve("src") + "/"
            }
        ],
        dedupe: ["vue"]
    },
    server: {
        open: true,
        host: "0.0.0.0",
    }
})
export default defineConfig(({command, mode}) => {
    console.log("当前命令:", command)
    console.log("当前模式:", mode)
    if (mode === 'serve') {
        console.log(command, mode)
        return {
            ...baseConfig
        }
    } else {
        // command === 'build'
        return {
            ...baseConfig
        }
    }
})
